package com.example.controller.aboutUser;

import com.example.vo.request.*;
import com.example.permission.PermissionCheck;
import com.example.service.aboutUser.UserService;
import com.example.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginForm loginForm, HttpSession session) {
        return userService.login(loginForm, session);
    }

    @GetMapping("/info")
    public Result userInfo() {
        return userService.userInfo();
    }

    @PostMapping("/register")
    public Result register(@RequestBody RegisterForm registerForm) {
        return userService.register(registerForm);
    }

    @GetMapping("/getAuthCode/{email}")
    public Result getAuthCode(@PathVariable String email) {
        return userService.getAuthCode(email);
    }

    @PutMapping("/resetPassword")
    public Result resetPassword(@RequestBody ForgetPasswordForm forgetPasswordForm) {
        return userService.resetPassword(forgetPasswordForm);
    }

    @GetMapping("/listUsers/{currentPage}/{pageSize}")
    public Result listUsers(@PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return userService.listUsers(currentPage, pageSize);
    }

    @PostMapping("/updateUserRoleAndPermissions")
    public Result updateUserRoleAndPermissions(@RequestBody UpdateUserRoleAndPermissionForm updateUserRoleAndPermissionForm) {
        return userService.updateUserRoleAndPermissions(updateUserRoleAndPermissionForm);
    }

    @PutMapping("/updateUserInfo")
    public Result updateUserInfo(@RequestBody UpdateUserInfoForm updateUserInfoForm, HttpSession session) {
        return userService.updateUserInfo(updateUserInfoForm, session);
    }

    @PostMapping("/checkPassword")
    public Result checkPassword(@RequestBody PasswordOperationForm passwordOperationForm) {
        return userService.checkPassword(passwordOperationForm);
    }

    @PutMapping("/updateUserPassword")
    public Result updateUserPassword(@RequestBody PasswordOperationForm changePasswordForm) {
        return userService.changePassword(changePasswordForm);
    }

    @GetMapping("/forbiddenAccount/{userId}")
    public Result forbiddenAccountByUserId(@PathVariable Integer userId) {
        return userService.forbiddenAccountByUserId(userId);
    }

    @GetMapping("/enableUserAccount/{userId}")
    public Result enableAccountByUserId(@PathVariable Integer userId) {
        return userService.enableAccountByUserId(userId);
    }

    @PostMapping("/listUsersByConditions")
    public Result listUsersByConditions(@RequestBody SearchUserConditions searchUserConditions) {
        return userService.listUsersByConditions(searchUserConditions);
    }
}
